import { useModel, useSnapshot } from '@@/exports'
import { ModalForm, ProFormText } from '@ant-design/pro-components'
import { ProFormInstance } from '@ant-design/pro-form/lib'
import { useRef } from 'react'

import { CollectionRecordModel } from '@/models/collectionRecord'

export interface CollectionRecorUpdateModalProps {
  onFinish: (formData: any) => Promise<boolean | void>
}

const CollectionRecorUpdateModal = (props: CollectionRecorUpdateModalProps) => {
  let { getDictList } = useModel('dict')
  let collectTionRecorState = useSnapshot(CollectionRecordModel.state)
  let { actions: collectTionRecorActions } = CollectionRecordModel
  const formRef = useRef<ProFormInstance>()
  return (
    <>
      <ModalForm
        key={collectTionRecorState.collectionRecord?.id || -1}
        formRef={formRef}
        title={collectTionRecorState.collectionRecord ? '修改奖品领取记录' : '添加奖品领取记录'}
        open={collectTionRecorState.updateModalState}
        initialValues={collectTionRecorState.collectionRecord}
        onFinish={props.onFinish}
        onOpenChange={collectTionRecorActions.setUpdateModalState}
      >
        <ProFormText label="活动id" name="activityId" rules={[{ required: true, message: '请填写活动id' }]} />

        <ProFormText label="活动名称" name="activityName" rules={[{ required: true, message: '请填写活动名称' }]} />

        <ProFormText label="奖品id" name="activityAwardId" rules={[{ required: true, message: '请填写奖品id' }]} />

        <ProFormText label="奖品名" name="activityAwardName" rules={[{ required: true, message: '请填写奖品名' }]} />

        <ProFormText label="公众号用户ID" name="mpUserId" rules={[{ required: true, message: '请填写公众号用户ID' }]} />

        <ProFormText label="公众号appId" name="mpAppId" rules={[{ required: true, message: '请填写公众号appId' }]} />

        <ProFormText label="小程序appId" name="maAppId" rules={[{ required: true, message: '请填写小程序appId' }]} />

        <ProFormText label="小程序openId" name="maOpenId" rules={[{ required: true, message: '请填写小程序openId' }]} />

        <ProFormText label="小程序用户id" name="maUserId" rules={[{ required: true, message: '请填写小程序用户id' }]} />

        <ProFormText label="公众号openId" name="mpOpenId" rules={[{ required: true, message: '请填写公众号openId' }]} />

        <ProFormText label="unionId" name="unionId" rules={[{ required: true, message: '请填写' }]} />
      </ModalForm>
    </>
  )
}

export default CollectionRecorUpdateModal
